/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kmcsoft.goldshop.shop.service.impl;

import com.kmcsoft.emaster.entity.Employee;
import com.kmcsoft.goldshop.model.master.Booth;
import com.kmcsoft.goldshop.model.master.JewelryStyle;
import com.kmcsoft.goldshop.model.master.ProductGold;
import com.kmcsoft.goldshop.model.master.Shop;
import com.kmcsoft.goldshop.shop.service.ShopService;
import com.kmcsoft.master.defaultservice.DefaultGenericService;
import java.util.Collection;

/**
 *
 * @author kmcsoft02
 */
public class JdoShopService extends DefaultGenericService implements ShopService {

    public Shop getShopById(Object id) {
        getPersistenceManager().getFetchPlan().addGroup("detach_Shop_All");
        getPersistenceManager().getFetchPlan().addGroup("detach_Employee_Email");
        getPersistenceManager().getFetchPlan().addGroup("detach_Employee_Positon");
        getPersistenceManager().getFetchPlan().addGroup("detach_Address_All");
        getPersistenceManager().getFetchPlan().addGroup("detach_Booth_All");
        getPersistenceManager().getFetchPlan().setMaxFetchDepth(-1);
        return getJdoTemplate().detachCopy(getJdoTemplate().getObjectById(Shop.class, id));
    }

    public Collection<Employee> getAllEmployee() {
        getPersistenceManager().getFetchPlan().addGroup("detach_Employee_Email");
        getPersistenceManager().getFetchPlan().addGroup("detach_Employee_Positon");
        getPersistenceManager().getFetchPlan().setMaxFetchDepth(-1);
        return getJdoTemplate().detachCopyAll(getJdoTemplate().find(Employee.class));
    }

    public String getBoothCodeByEmployee(Employee emp) {
        Collection<Booth> booths =getJdoTemplate().find(Booth.class);
        for(Booth booth:booths){
            if(booth.getEmployees().contains((Employee)emp)){
                return booth.getCode();
            }
        }
        return "";
    }
}
